import json
import os
import unittest

import pytest

from APIs.general import General
from Common.load_case import LoadCase
from Common.reader import Reader
from main import CONFIG_INI

CASES = LoadCase().get_case()
reader = Reader()
config = reader.read_ini(CONFIG_INI)
headers = {
    "Content-Type": "application/json",
}


class TestLogin:
    @pytest.mark.parametrize('case', CASES['sys_user_login'])
    def test_login(self, case):
        url = os.path.join(config['project']['pre_url'], 'sys_user_login'.replace('_', '/'))
        general = General(url, headers, case['Test_case'])
        result = general.send_post()
        print(result)


@pytest.mark.parametrize('login', [config], indirect=True)
class TestProject:
    @pytest.mark.parametrize('case', CASES['project_saveProject'])
    def test_saveProject(self, login,case):
        code,token = login
        headers['Authorization'] = token
        url = os.path.join(config['project']['pre_url'], 'project_saveProject'.replace('_', '/'))
        general = General(url, headers, case['Test_case'])
        result = general.send_put()
        print(result)

